<?php
namespace app\index\controller;

use \think\Controller;
//use think\facade\Request;
use think\Db;
use think\facade\Request;
use app\index\controller\Base;
class Product extends  Controller
{
	public function index()
	{
		$id = input('id');
		//商品
		$good = Db::table('shop_goods')
		->field('shop_goods.id as id,goods_name,goods_cate_name,goods_imgs,goods_summary,goods_desctipt')
		->join('shop_goods_cate','shop_goods.goods_cate_id=shop_goods_cate.id','left')
		->where('shop_goods.id',$id)
		->find();
		//商品款式
		$goodstyle = Db::table('shop_goods_detail')
		->field('shop_goods_detail.id as id,goods_summary,goods_price,special,discount,color_img,goods_num')
		->join('shop_goods','shop_goods.id=shop_goods_detail.shop_goods_id','left')
		->where('shop_goods.id',$id)
		->select();
		//轮播图
		$goodsimg = $good['goods_imgs'];
		$goodsimg = json_decode($goodsimg);
		
		//其他商品
		$othergood = Db::table('shop_goods')
		->field('shop_goods.id as id,goods_name,goods_cate_name,goods_imgs,goods_price,goods_num,goods_thumb')
		->join('shop_goods_cate','shop_goods.goods_cate_id=shop_goods_cate.id','left')
		->join('shop_goods_detail','shop_goods.id=shop_goods_detail.shop_goods_id','left')
		->where('shop_goods.id','<>',$id)
		->where('goods_cate_name',$good['goods_cate_name'])
		->order('weight', 'desc')
		->limit(4)
		->select();
		
		$this->assign(['good'=>$good,'goodstyle'=>$goodstyle,'goodsimg'=>$goodsimg,'othergood'=>$othergood]);
//		dump($good);
//		dump($othergood);
//		exit;	
		return $this->fetch();
	}
	public function getprice()
	{
		$id = input('id');
		$re = Db::table('shop_goods_detail')->where('id',$id)->find();
		echo $re['goods_price'];
	}
	public function getnum()
	{
		$id = input('id');
		$re = Db::table('shop_goods_detail')->where('id',$id)->find();
		echo $re['goods_num'];
	}
	
}